package com.business.user;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.beans.user.UserInfo;
import com.sql.DBFactory;

public class UserListBus {
	private Connection conn = null;

	private Statement stmt = null;

	private ResultSet rs = null;

	private static final Log log = LogFactory.getLog(UserListBus.class);

	public UserInfo getUserInfo(String username) {
		UserInfo ui = new UserInfo();
		String sql = "select * from user_info where username ='" + username
				+ "'";
		try {
			conn = DBFactory.getConnection();
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			if (rs.next()) {
				ui.setBlogMemo(rs.getString("blog_memo"));
				ui.setPassword(rs.getString("password"));
				ui.setUsername(rs.getString("username"));
				ui.setUserHomepage(rs.getString("user_homepage"));
				ui.setUserNickname(rs.getString("user_nickname"));
				ui.setUserEmail(rs.getString("user_Email"));
				ui.setUserqq(rs.getString("userqq"));
				ui.setAddress(rs.getString("address"));
				ui.setAnswer(rs.getString("answer"));
				ui.setAsk(rs.getString("ask"));
				ui.setBirthday(rs.getString("birthday"));
				ui.setBlogName(rs.getString("blog_name"));
				ui.setCity(rs.getString("city"));
				ui.setGonggao(rs.getString("gonggao"));
				ui.setIsOpen(rs.getString("isOpen"));
				ui.setLastloginTime(rs.getString("lastlogin_time"));
				ui.setLoginCount(rs.getString("login_count"));
				ui.setMobile(rs.getString("mobile"));
				ui.setMsn(rs.getString("msn"));
				ui.setProvince(rs.getString("province"));
				ui.setRegTime(rs.getString("reg_time"));
				ui.setSex(rs.getString("sex"));
				ui.setTelephone(rs.getString("telephone"));
				ui.setUserLastIp(rs.getString("user_lastIP"));
				ui.setUserLove(rs.getString("user_love"));
				ui.setUserIntro(rs.getString("user_intro"));
				ui.setIsHide(rs.getString("isHide"));
				ui.setUserPhotourl(rs.getString("user_photourl"));
			}
		} catch (Exception e) {
			log.error("the select userlist exception:" + e.getMessage());
			log.error("the select userlist sql is: " + sql);
		} finally {
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException sqle) {
				log.error(sqle.toString());
			}
		}
		return ui;
	}
	public UserInfo getUserById(String id) {
		UserInfo ui = new UserInfo();
		String sql = "select * from user_info where user_id =" + id	;
		try {
			conn = DBFactory.getConnection();
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			if (rs.next()) {
				ui.setBlogMemo(rs.getString("blog_memo"));
				ui.setPassword(rs.getString("password"));
				ui.setUsername(rs.getString("username"));
				ui.setUserHomepage(rs.getString("user_homepage"));
				ui.setUserNickname(rs.getString("user_nickname"));
				ui.setUserEmail(rs.getString("user_Email"));
				ui.setUserqq(rs.getString("userqq"));
				ui.setAddress(rs.getString("address"));
				ui.setAnswer(rs.getString("answer"));
				ui.setAsk(rs.getString("ask"));
				ui.setBirthday(rs.getString("birthday"));
				ui.setBlogName(rs.getString("blog_name"));
				ui.setCity(rs.getString("city"));
				ui.setGonggao(rs.getString("gonggao"));
				ui.setIsOpen(rs.getString("isOpen"));
				ui.setLastloginTime(rs.getString("lastlogin_time"));
				ui.setLoginCount(rs.getString("login_count"));
				ui.setMobile(rs.getString("mobile"));
				ui.setMsn(rs.getString("msn"));
				ui.setProvince(rs.getString("province"));
				ui.setRegTime(rs.getString("reg_time"));
				ui.setSex(rs.getString("sex"));
				ui.setTelephone(rs.getString("telephone"));
				ui.setUserLastIp(rs.getString("user_lastIP"));
				ui.setUserLove(rs.getString("user_love"));
				ui.setUserIntro(rs.getString("user_intro"));
				ui.setIsHide(rs.getString("isHide"));
				ui.setUserPhotourl(rs.getString("user_photourl"));
			}
		} catch (Exception e) {
			log.error("the select userlist exception:" + e.getMessage());
			log.error("the select userlist sql is: " + sql);
		} finally {
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException sqle) {
				log.error(sqle.toString());
			}
		}
		return ui;
	}
}
